<template>
  <div class="my_div">
    <img src="https://scpic.chinaz.net/files/pic/pic9/202003/zzpic23514.jpg" alt="" />
    <p :style="{backgroundColor: color}" @click="btn">这是一个孤独可怜的狗</p>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        color: ''
      }
    },
    methods: {
      btn() {
        this.color =
          `rgb(${Math.floor(Math.random() * 256)}, ${Math.floor(Math.random() * 256)}, ${Math.floor(Math.random() * 256)})`
      }
    }
  };
</script>

<style>
  .my_div {
    width: 400px;
    border: 1px solid black;
    text-align: center;
    float: left;
  }

  .my_div img {
    width: 100%;

  }
</style>